import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:personinfo/utils/ColorUtil.dart';

import '../../../widgets/common/CommonWidget.dart';
import '../../../widgets/common/keepAlive/KeepAliveWrapper.dart';
import 'widgets/OrderInfo.dart';

class OrderList extends StatefulWidget {
  Map arguments;
  OrderList({super.key,required this.arguments});

  @override
  State<StatefulWidget> createState() => _OrderList();
}

class _OrderList extends State<OrderList> with SingleTickerProviderStateMixin {
  late TabController _tabController;
  List tabs = ["待处理", "待确认", "待支付","已完成",'已取消'];
  final List _pages = [
    const OrderInfo(orderNum: "X1111-待处理",),
    const OrderInfo(orderNum: "X22222-待确认",),
    const OrderInfo(orderNum: "X3333-待支付",),
    const OrderInfo(orderNum: "X4444-已完成",),
    const OrderInfo(orderNum: "X5555-已取消",)
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: tabs.length,initialIndex: widget.arguments['index'] ?? 0, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  Scaffold(
      appBar: commonWidget.appBar(
        title: const Text("我的订单") ,
        leading: GestureDetector(onTap: (){Navigator.pop(context);},child: const Icon(Icons.keyboard_arrow_left),),
        bottom: PreferredSize(
            preferredSize: Size.fromHeight(50.0),
            child: Container(
              decoration: BoxDecoration(
                  color: Theme.of(context).colorScheme.onPrimary
              ),
              child: TabBar(
                controller: _tabController,
                padding: EdgeInsets.fromLTRB(1, 0, 1, 1),
                unselectedLabelColor: Colors.black,
                labelStyle: TextStyle(fontWeight: FontWeight.bold,color: Colors.black),
                indicatorColor:  ColorUtil.primaryBgColor,
                tabs: tabs.map((e) => SizedBox(width: 100,child: Tab(text: e,))).toList(),
              ),
            )
        ),
      ),
      body: TabBarView(
        //构建
        controller: _tabController,
        children: _pages.map((e) {
          return KeepAliveWrapper(
            child: Container(
              alignment: Alignment.center,
              child: e,
            ),
          );
        }).toList(),
      ),
    );
  }

  @override
  void dispose() {
    // 释放资源
    _tabController.dispose();
    super.dispose();
  }
}
